home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
DAKEY.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-08-03
|
5KB
|
153 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: dakey.c
// Title: Data File Build Utility Library
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
//
// This module contains code to manage and create sort keys.
//
// The code in this module should be written entirely in C.
// Do not use any C++ constructs.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
// SCO UNIX.
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
// SCO UNIX cc
//
//----------------------------------------------------------------------------
#include <da.h>
//----------------------------------------------------------------------------
// Description:
// Parameters: pcfg Configuration file information
// Returns:
//----------------------------------------------------------------------------
SIZET FN_E DataField(PDATACFG pcfg, PCSZ pcsz)
{
SIZET i;
Assert(pcfg);
Assert(pcsz && pcsz[0]);
for (i = 0; i < pcfg->cFields; ++i)
if (stricmp(pcfg->afld[i].szName, pcsz) == 0)
return i;
Halt("Invalid field name!");
return 0;
}
//----------------------------------------------------------------------------
// Description: Create the sort key for a particular record.
// Parameters: pdlmrec Delimited file data
// psz Buffer for key.
// Assumed to be of sufficient size.
// This buffer is NOT null terminated at exit.
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
VOID FN_E DataKey(PDLMREC pdlmrec, PSZ psz)
{
SIZET cKeys = pdlmrec->pcfg->cKeys;
PDATAFLD pfld = pdlmrec->pcfg->afld;
PSIZET pcKey = pdlmrec->pcfg->acKey;
SIZET i, j;
SIZET cLen;
PSZ pszKey;
for (i = 0; i < cKeys; ++i)
{
BOOL fAlpha = TRUE;
j = pcKey[i]; // Get data about key
cLen = pfld[j].cSort ? pfld[j].cSort: pfld[j].cLen;
pszKey = pdlmrec->apsz[j];
memset(psz, 0, cLen); // Start by blanking field
if (pfld[j].fs & FLD_NUMERIC) // Numeric field -- right justify
{ // Verify field is all numeric
SIZET cDig, cLead = 0;
// Dashes signify leading zeroes
for (cLead = 0; pszKey[cLead] == '-'; cLead++)
;
for (cDig = cLead; pszKey[cDig]; ++cDig)
if (!isascii(pszKey[cDig]) || !isdigit(pszKey[cDig]))
break;
if (cDig) // Copy into buffer -- left justified
{ // Only use numeric portion in bcd format
Assert(cLen > 1);
cDig = MIN(cLen * 2, cDig - cLead);
if (cDig)
stra2b((PBYTE)psz, cLen, pszKey + cLead, cDig);
fAlpha = FALSE;
}
}
if (fAlpha)
{
SIZET cStr;
if (BTEST(pfld[j].fs, FLD_FIXED))
cStr = MIN(cLen, pfld[j].cLen);
else
cStr = strlen(pszKey); // Copy alpha, left justified
cStr = MIN(cLen, cStr);
if (cStr)
memcpy(psz, pszKey, cStr);
}
psz += cLen; // Move to start of next field
}
return ;
}
//----------------------------------------------------------------------------
// Description: Compute the size of the current sort key.
// Parameters: pcfg Configuration file information
// Returns: Size of key.
//----------------------------------------------------------------------------
SIZET FN_E DataKeyLen(PDATACFG pcfg)
{
PDATAFLD pfld = pcfg->afld;
PSIZET pcKey = pcfg->acKey;
SIZET cKeys = pcfg->cKeys;
SIZET i;
SIZET cSize = 0;
for (i = 0; i < cKeys; ++i)
cSize += pfld[pcKey[i]].cSort ? pfld[pcKey[i]].cSort: pfld[pcKey[i]].cLen;
return cSize;
}
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------